package com.winterwar.dao.hibernate;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.winterwar.base.Registration;
import com.winterwar.dao.RegistrationDAO;


public class RegistrationDAOHibernate extends HibernateDaoSupport implements RegistrationDAO{
	
	private Log log = LogFactory.getLog(RegistrationDAO.class);

	public Registration get(Integer regID) {
		return (Registration) getHibernateTemplate().get(Registration.class, regID);
	}

	public List getAll() {
		return getHibernateTemplate().find("from Registration");
	}

	public void remove(Integer regID) {
		Object registration = getHibernateTemplate().load(Registration.class, regID);
		getHibernateTemplate().delete(registration);
		getHibernateTemplate().flush();
	}

	public void save(Registration registration) {
		getHibernateTemplate().saveOrUpdate(registration);
		getHibernateTemplate().flush();
		if(log.isDebugEnabled()){
			log.debug("New Registration ID is : " + registration.getRegID());
		}
	}

	public List getByConID(Integer conID, String status) {
		String clause = "from Registration where conID = " + conID;
		if(status != null && !status.equals(""))
			clause = clause + " and status = " + status;
		return getHibernateTemplate().find(clause);
	}
}
